/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __QS_DBDayFile_H__
#define __QS_DBDayFile_H__

#include <string>
#include <map>

#include "StockInfo.h"

namespace QSThink
{
	class DBDayIndexFile
	{
	public:
		static const int DAY_MAX=64*1024;
		static const std::string IndexFileName;

	public:
		DBDayIndexFile();

		//return the day index
		int addDay(int day);

		int getDayCount();

		bool hasDay(int day);
		int getDayIndex(int day);

	protected:
		int _dayCount;//how many day file we created
		int _days[DAY_MAX];//64*1024 day about 180 year enough?

		std::map<int,int> _dayMap;
	};


	/*At a specified day inner present
	*/
	class StockDayInfo
	{
	public:
		StockDayInfo();

		void set(int symbol,int openPrice,int closePrice,
			int highPrice,int lowPrice,int volume,int amount);


		int flag;//now 0 means not used 1 means used.
		//int day;//from 1900 already organized by day
		int symbol;//600 000 start

		int openPrice;//today open market price and multiply it by 100
		int closePrice;//last day close market price  and multiply it by 100

		int highPrice;//high Price of the day  and multiply it by 100
		int lowPrice;//low price of the day and multiply it by 100

		int volume;//trade volume and multiply it by 100
		int amount;//trade amount(total trade value(RMB)) and multiply it by 100

		int unused[8];

		//total 16*4=64 bytes. so a file max 64K

	};


	
	/*manipulate stock DB day data
	*/
	class DBDayFile
	{
	public:
		static const int StockMax=1024;//but shanghai + shenzhen will exceed this
	public:
		DBDayFile(int day);

		StockDayInfo* getStockInfo(int symbol );

		//persist stock info at location index
		void persit(int index,StockInfo info);

	protected:
		std::string _fileName;//day.data
		int _day;//the day from 1900
		StockDayInfo _stock[StockMax];
		
	};


}

#endif
